﻿#region

using Microsoft.AspNetCore.HttpLogging;

#endregion

namespace Vin.Extension.HttpLogging;

public class VinHttpLoggingInterceptor : IHttpLoggingInterceptor
{
    public ValueTask OnRequestAsync(HttpLoggingInterceptorContext logContext)
    {
        return ValueTask.CompletedTask;
    }

    public ValueTask OnResponseAsync(HttpLoggingInterceptorContext logContext)
    {
        // var list = logContext.HttpContext.Features;
        // var requestBody = logContext.HttpContext.Request.Body;
        // var responseBody = logContext.HttpContext.Features.Get<IHttpResponseBodyFeature>();
        // var requestBodyString = string.Empty;
        // var responseBodyString = string.Empty;
        // if (requestBody.CanSeek)
        // {
        //     requestBody.Seek(0, System.IO.SeekOrigin.Begin);
        //     requestBodyString = new System.IO.StreamReader(requestBody).ReadToEnd();
        // }
        //     
        // if (responseBody != null && responseBody.Stream.CanRead)
        // {
        //     responseBody.Stream.Seek(0, System.IO.SeekOrigin.Begin);
        //     responseBodyString = new System.IO.StreamReader(responseBody.Stream).ReadToEnd();
        // }
        // Console.WriteLine("OnResponseAsync" + JsonSerializer.Serialize(logContext.Parameters));
        //
        return ValueTask.CompletedTask;
    }
}